package org.osomit.sacct.security.otp.impl;

import org.osomit.sacct.security.otp.impl.OTPTokenImpl;
import org.osomit.sacct.security.otp.impl.HOTPAlgorithm;
import org.osomit.sacct.security.otp.impl.XMLOTPTokenGenerator;
import org.osomit.sacct.security.otp.iface.OTPToken;
import org.junit.Test;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;

/**
 * @author Jian Fang (John.Jian.Fang@gmail.com)
 * 
 * Date: Jun 26, 2009
 */
public class XMLOTPTokenGenerator_UT {
	private static String SECRET_STRING = "12345678901234567890";
	private static HOTPAlgorithm algorithm;

	@BeforeClass
	public static void singleSetup(){
		algorithm = new HOTPAlgorithm();
	}

	@AfterClass
	public static void singleTearDown() {
		algorithm = null;
	}

	@Test
	public void testGenerateToken(){
		long initCount = 100;
		int codeDigits = 9;
		boolean addChecksum = true;
		int truncationOffset = 20;
		String SN = "321151351351";
		String password = "good4you";
		int stepSize = 100;

		OTPToken token = new OTPTokenImpl(SN, SECRET_STRING.getBytes(), initCount, codeDigits,
				addChecksum, truncationOffset, stepSize, algorithm);
		try {
			String result = XMLOTPTokenGenerator.generateToken(token, password);
			assertNotNull(result);
			result = XMLOTPTokenGenerator.generateToken(SN, SECRET_STRING, initCount,
					System.currentTimeMillis(), codeDigits, addChecksum, truncationOffset, stepSize, password);
			assertNotNull(result);
		} catch (Exception e) {
			e.printStackTrace();
			fail(e.getMessage());
		}
	}
}
